package cn.jhc.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jhc.dao.AuthorDAO;
import cn.jhc.dao.DaoType;
import cn.jhc.dao.PublisherDAO;
import cn.jhc.dao.UserDao;
import cn.jhc.factory.DAOFactory;

/**
 * Servlet implementation class DelPublisherServlet
 */
@WebServlet("/delauthor.htm")
public class DeleteAuthorServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;



	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
//		String authorId = request.getParameter("id");
//		int id = Integer.parseInt(authorId);
//		AuthorDAO adao = (AuthorDAO)DAOFactory.getDao(DaoType.AUTHOR);
//		adao.deleteAuthors(id);
		
	
		String par = request.getParameter("oneid");
		if(par == null){
			String[] str = request.getParameterValues("authorid");
			for(String s : str){
				int id = Integer.parseInt(s);
				AuthorDAO pdao = (AuthorDAO)DAOFactory.getDao(DaoType.AUTHOR);
				pdao.deleteAuthors(id);
			}
		}
		else{
			int id = Integer.parseInt(par);
			AuthorDAO pdao = (AuthorDAO)DAOFactory.getDao(DaoType.PUBLISHER);
			pdao.deleteAuthors(id);
		}
		request.getRequestDispatcher("/admin/admin.jsp?body=/showauthors.htm").forward(request, response);
	}
	

}
